package com.ktjiaoyu.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ktjiaoyu.server.mapper.AdminMapper;
import com.ktjiaoyu.server.pojo.Admin;
import com.ktjiaoyu.server.service.IAdminService;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserDetailServiceImpl implements UserDetailsService {
    @Resource
    IAdminService adminService;

    @Override
    public UserDetails loadUserByUsername(String username)
            throws UsernameNotFoundException {
        // 实现通过用户名查询用户详情对象信息
        Admin admin = adminService.getAdminByUserName(username);
        if (null != admin) {
            admin.setRoles(adminService.findRolesAndMenusByAdminId(admin.getId()));
            return admin;
        }
        throw new UsernameNotFoundException("用户名密码不正确");

    }
}
